//
//  MyPageViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2017/10/12.
//  Copyright © 2017年 李 佳伟. All rights reserved.
//

#import "MyPageViewController.h"
#import "JTCSM.h"
#import "BottomBtnView.h"
#import "MyHeaderView.h"
#import "MyInfoView.h"
#import "MyBankCardViewController.h"
#import "GetInfoClass.h"
#import "BonusViewController.h"
#import "NewPersonViewController.h"
#import "BanBenInfoViewController.h"
#import "ChongzhiViewController.h"
#import "JiangLijinViewController.h"
#import "TiXianViewController.h"
#import "NewFeiLvViewController.h"
#import "TrueNameViewController.h"
#import "ChangePasswordViewController.h"
#import "ShareViewController.h"
#import "NewSettingViewController.h"
#import "NewMoreViewController.h"
#import "NewPersonInfoViewController.h"
#import "NewFuLiViewController.h"
#import "NewMessageViewController.h"
#import "NewJiesuanViewController.h"
#import "NewQianBaoViewController.h"

static CGFloat myinfoHeight = 50;
@interface MyPageViewController ()<UINavigationControllerDelegate>
{
    CGFloat gongjulanHeight;
    BottomBtnView *aboutWebV;
    MyHeaderView *view;
    UIScrollView *backScrollV;
    NSString *is_verified;
    MyInfoView*changeView;
    UIView *headerView;
    
    UIImageView *logoImageV;
    UIImageView *huiyuanImageV;
    UILabel *nameLabel;
    UILabel *huiyuanLabel;
    UIImageView *erweimaImageV;

}
@end

@implementation MyPageViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    self.navigationController.delegate = self;
    [df isRemoveTarbar:NO];
    [[GetInfoClass shareSingle] getinfo];
    [GetInfoClass shareSingle].myblock = ^(UserInfoModel *Model) {
        
        [view setvalueWithUserInfoModel:Model];
        is_verified = Model.is_verified;
        [self changeStatus];
        
        MyInfoView *myview = [backScrollV viewWithTag:111];
        myview.footerLabel.text = Model.tel;
    };
}
- (void)gotoAddBankVC{
    NewSettingViewController *vc = [[NewSettingViewController alloc]init];
    vc.nameTitle = @"设置";
    [self.navigationController pushViewController:vc animated:YES];
}
// 将要显示控制器
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewDidLoad{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    leftBarButtonItems_rightBarButtonItems *leftbtn = KCUSTOMNAVIGSTION_ALLOC;
    self.navigationItem.rightBarButtonItem = [leftbtn setBarButtonItemsTitle:@"设置" frame:KRightBarButtonItemFrame_text target:self SEL:@selector(gotoAddBankVC)];
//    self.navigationController.navigationBar.hidden = YES;
    backScrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, KagainChangeHeight, KCONTROLLERWith, KCONTROLLERHeight)];
    backScrollV.backgroundColor = [UIColor whiteColor];
    backScrollV.userInteractionEnabled = YES;
    backScrollV.bounces = NO;
    backScrollV.showsVerticalScrollIndicator = NO;
    [self.view addSubview:backScrollV];

//    view = [[MyHeaderView alloc]init];
//    [backScrollV addSubview:view];
//    [self layoutTypeView];
    [self setHeaderView];
    [self layoutMyinfoView];
    
    
}

- (void)layoutTypeView{
    
    if (KSCREENWidth==375) {
        gongjulanHeight = 100;
    }else if(KSCREENWidth==320){
        gongjulanHeight = 80;
    }else{
        gongjulanHeight = 100;
    }
    
   NSArray *titlearr = @[@"充值",@"奖励金",@"提现"];
    
    for (int i = 0 ; i<titlearr.count; i++) {
        
        aboutWebV = [[BottomBtnView alloc]initWithFrame:CGRectMake(KSCREENWidth/titlearr.count*i,KVIEW_Y(view), KSCREENWidth/titlearr.count, gongjulanHeight) title:titlearr[i] imageName:[NSString stringWithFormat:@"icon_%d@2x.png",i+16]];
        aboutWebV.backgroundColor = [UIColor whiteColor];
        aboutWebV.tag = 200+i;
        aboutWebV.label.font = [UIFont systemFontOfSize:14];
        [df layerWithView:aboutWebV.imgView radius:aboutWebV.imgView.frame.size.height/2 width:0 color:nil];
        [backScrollV addSubview:aboutWebV];
        [df  addTapGestureRecognizerWithTarget:self action:@selector(touchTitleView:) andaddView:aboutWebV];
    }

}

- (void)touchTitleView:(UITapGestureRecognizer *)tap {
    
    NSInteger tagnum = [tap view].tag ;
    switch (tagnum) {
        case 200:
            [self gotoChongZhiVC];
            break;
        case 201:
            [self gotojianglijinVC];
            break;
        case 202:
            [self gotoTiXianVC];
            break;
            
        default:
            break;
    }
    
}

- (void)gotoChongZhiVC{
    ChongzhiViewController *vc = [[ChongzhiViewController alloc]init];
    vc.nameTitle = @"账户充值";
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)gotojianglijinVC{
    JiangLijinViewController *vc = [[JiangLijinViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)gotoTiXianVC{
    TiXianViewController *vc = [[TiXianViewController alloc]init];
    vc.nameTitle = @"提现";
    [self.navigationController pushViewController:vc animated:YES];
}


#pragma mark newSetView

- (void)setHeaderView{
    NSString *nameStr = @"DEMON";
    float fontsize = 16;
    CGFloat changeSpace = 12;
    CGFloat headerHeight = 90;
    CGRect rect = [df labelHeightWithContent:nameStr width:1000 font:fontsize];
    headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, headerHeight)];
    headerView.backgroundColor = [UIColor whiteColor];
    [backScrollV addSubview:headerView];
    headerView.userInteractionEnabled = YES;
    [df addTapGestureRecognizerWithTarget:self action:@selector(gotoPersonInfoVC) andaddView:headerView];
    
    CGFloat imagesize = rect.size.height*2+changeSpace;
    CGFloat top = (headerHeight-imagesize)/2;
    
    logoImageV = [[UIImageView alloc]initWithFrame:CGRectMake(20, top, imagesize, imagesize)];
    logoImageV.image = [UIImage imageNamed:@"我的_头像.png"];
    [headerView addSubview:logoImageV];
    logoImageV.userInteractionEnabled = YES;
    [df layerWithView:logoImageV radius:imagesize/2 width:0 color:nil];
    CGFloat huiyuanImageSize = 15;
    huiyuanImageV = [[UIImageView alloc]initWithFrame:CGRectMake(KVIEW_X(logoImageV)-10, KVIEW_Y(logoImageV)-10, huiyuanImageSize, huiyuanImageSize)];
    huiyuanImageV.image = [UIImage imageNamed:@"我的_认证.png"];
    [headerView addSubview:huiyuanImageV];
    huiyuanImageV.userInteractionEnabled = YES;
    
    nameLabel = [UILabel initWithFrame:CGRectMake(KVIEW_X(logoImageV)+20, top, KCONTROLLERWith/2, rect.size.height) text:nameStr font:fontsize textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(51, 51, 51, 1) backgroundColor:nil];
    [headerView addSubview:nameLabel];
    nameLabel.userInteractionEnabled = YES;
    
    huiyuanLabel = [UILabel initWithFrame:CGRectMake(KVIEW_X(logoImageV)+20, KVIEW_Y(nameLabel)+changeSpace, 0, rect.size.height+5) text:@"" font:0 textAlignment:NSTextAlignmentCenter texcolor:RGBACOLOR(51, 51, 51, 1) backgroundColor:KZhuTiRGB];
    [headerView addSubview:huiyuanLabel];
    [self setHuiYuanLabelFrameWithTitle:@"天使会员"];
    huiyuanLabel.userInteractionEnabled = YES;
    CGFloat fanhuiImagesize = 15;
    UIImageView *fanhuiImageV = [[UIImageView alloc]initWithFrame:CGRectMake(KCONTROLLERWith-20-fanhuiImagesize, (headerHeight-fanhuiImagesize)/2, fanhuiImagesize, fanhuiImagesize)];
    fanhuiImageV.image = [UIImage imageNamed:@"myFanhui.png"];
    [headerView addSubview:fanhuiImageV];
    fanhuiImageV.userInteractionEnabled = YES;
    CGFloat erweimaIamgesize = 25;
    erweimaImageV = [[UIImageView alloc]initWithFrame:CGRectMake(fanhuiImageV.frame.origin.x-erweimaIamgesize-5, (headerHeight-erweimaIamgesize)/2, erweimaIamgesize, erweimaIamgesize)];
    erweimaImageV.image = [UIImage imageNamed:@"我的_二维码.png"];
    [headerView addSubview:erweimaImageV];
    erweimaImageV.userInteractionEnabled = YES;

}
- (void)setHuiYuanLabelFrameWithTitle:(NSString *)title{
   
    huiyuanLabel.font = [UIFont systemFontOfSize:11];
    huiyuanLabel.text = title;
    CGRect rect = [df labelHeightWithContent:title width:1000 font:11];
    huiyuanLabel.frame = CGRectMake(huiyuanLabel.frame.origin.x, huiyuanLabel.frame.origin.y, rect.size.width+10, huiyuanLabel.frame.size.height);
    [df layerWithView:huiyuanLabel radius:huiyuanLabel.frame.size.height/2 width:0 color:nil];
    
}

- (void)layoutMyinfoView{
    
    NSArray *array = @[@"我的钱包"];
    NSArray *iamgearray = @[@"我的_钱包.png"];
    NSArray *array1 = @[@"福利",@"消息",@"费率"];
    NSArray *imagearray1 = @[@"我的_福利.png",@"我的_消息.png",@"我的_费率.png"];
    NSArray *array2 = @[@"结算卡",@"更多服务"];
    NSArray *imagearray2 = @[@"我的_结算卡.png",@"我的_更多服务.png"];
    [df lineViewWithHeightofTop:KVIEW_Y(headerView)+10 superView:backScrollV spacing:0 color:RGBACOLOR(241, 241, 241, 1) lineHeight:10];
    for (int i = 0; i < array.count; i++) {
        MyInfoView *view1 = [[MyInfoView alloc]initWithFrame:CGRectMake(0, KVIEW_Y(headerView)+10+myinfoHeight*i, KCONTROLLERWith, myinfoHeight) imagename:iamgearray[i] title:array[i]placeholder:nil isShowLabel:ImageViewType radioBtnIndex:0 GroupId:@""];
        view1.tag = 100+i;
        view1.userInteractionEnabled = YES;
        view1.lineView.hidden = YES;
        [df addTapGestureRecognizerWithTarget:self action:@selector(gotoVC:) andaddView:view1];
        [backScrollV addSubview:view1];
    }
    [df lineViewWithHeightofTop:KVIEW_Y(headerView)+myinfoHeight*array.count+20 superView:backScrollV spacing:0 color:RGBACOLOR(241, 241, 241, 1) lineHeight:10];
    for (int i = 0; i < array1.count; i++) {
        MyInfoView *view2 = [[MyInfoView alloc]initWithFrame:CGRectMake(0, KVIEW_Y(headerView)+myinfoHeight*array.count+20+myinfoHeight*i, KCONTROLLERWith, myinfoHeight) imagename:imagearray1[i] title:array1[i]placeholder:nil isShowLabel:ImageViewType radioBtnIndex:0 GroupId:@""];
        view2.tag = 200+i;
        view2.userInteractionEnabled = YES;
        [df addTapGestureRecognizerWithTarget:self action:@selector(gotoVC:) andaddView:view2];
        [backScrollV addSubview:view2];
        if (i == array1.count-1) {
            view2.lineView.hidden = YES;
        }
    }
    [df lineViewWithHeightofTop:KVIEW_Y(headerView)+myinfoHeight*(array.count+array1.count)+30 superView:backScrollV spacing:0 color:RGBACOLOR(241, 241, 241, 1) lineHeight:10];
    for (int i = 0; i < array2.count; i++) {
        MyInfoView *view3 = [[MyInfoView alloc]initWithFrame:CGRectMake(0, KVIEW_Y(headerView)+myinfoHeight*(array.count+array1.count)+30+myinfoHeight*i, KCONTROLLERWith, myinfoHeight) imagename:imagearray2[i] title:array2[i]placeholder:nil isShowLabel:ImageViewType radioBtnIndex:0 GroupId:@""];
        view3.tag = 300+i;
        view3.userInteractionEnabled = YES;
        [df addTapGestureRecognizerWithTarget:self action:@selector(gotoVC:) andaddView:view3];
        [backScrollV addSubview:view3];
        [backScrollV setContentSize:CGSizeMake(KCONTROLLERWith, KVIEW_Y(view3))];
    }
    
}

#pragma mark 跳转个人信息
- (void)gotoPersonInfoVC{
    NewPersonInfoViewController *vc = [[NewPersonInfoViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)gotoVC:(UITapGestureRecognizer *)tap{
    MyInfoView *myview = (MyInfoView *)[tap view];
    
    switch (myview.tag) {
        case 100:
            [self gotoQianBaoVC];
            break;
        case 200:
            [self gotoNewFuLiVC];
            break;
        case 201:
            [self gotoMessageVC];
            break;
        case 202:
            [self gotoFeiLvVC];
            break;
        case 300:
            [self gotoNewJiesuanVC];
            break;
        case 301:
            
            [self gotoNewMoreVC];
            break;
            
        default:
            break;
    }
}



- (void)gotoNewJiesuanVC{
    NewJiesuanViewController *vc = [[NewJiesuanViewController alloc]init];
    vc.nameTitle = @"结算卡";
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)gotoMessageVC{
    NewMessageViewController *vc = [[NewMessageViewController alloc]init];
    vc.nameTitle = @"消息";
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)gotoNewFuLiVC{
    NewFuLiViewController *vc = [[NewFuLiViewController alloc]init];
    vc.nameTitle = @"福利";
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark  分享
- (void)sharevc{
    ShareViewController *vc = [[ShareViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
    
}

- (void)gotoQianBaoVC{
    NewQianBaoViewController *vc = [[NewQianBaoViewController alloc]init];
    vc.nameTitle = @"钱包";
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)gotoTrueNameVC{
    TrueNameViewController *vc = [[TrueNameViewController alloc]init];
    vc.nameTitle = @"实名认证";
    [self.navigationController pushViewController:vc animated:NO];

}
//跳转HongbaoVC
- (void)gotoHongBaoVC{
    BonusViewController *vc = [[BonusViewController alloc]init];
    vc.nameTitle = @"我的红包";
    [self.navigationController pushViewController:vc animated:YES];
}

//跳转新人专区VC
- (void)gotoNewPersongVC{
    NewPersonViewController *vc = [[NewPersonViewController alloc]init];
    vc.nameTitle = @"新人专区";
    [self.navigationController pushViewController:vc animated:YES];
}
//跳转费率VC
- (void)gotoFeiLvVC{
    NewFeiLvViewController *vc = [[NewFeiLvViewController alloc]init];
    vc.nameTitle = @"我的费率";
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark 更多功能VC
- (void)gotoNewMoreVC{
    NewMoreViewController *vc = [[NewMoreViewController alloc]init];
    vc.nameTitle = @"更多服务";
    [self.navigationController pushViewController:vc animated:YES];
}


//跳转版本信息VC
- (void)gotoBanbeninfovc{
    
    
    BanBenInfoViewController *vc = [[BanBenInfoViewController alloc]init];
    vc.nameTitle = @"版本信息";
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)changeStatus{
    CGFloat font = 12;
    CGFloat changeSize = 8;
    
    NSString *labeltext ;
    if ([is_verified isEqualToString:@"0"]) {
        labeltext= @"未认证";
        CGRect rect = [df labelHeightWithContent:labeltext height:myinfoHeight font:font];
        changeView.footerLabel.frame = CGRectMake(changeView.frame.size.width-10-changeSize-rect.size.width, (myinfoHeight -rect.size.height-8)/2, rect.size.width+8, rect.size.height+8);
        changeView.footerLabel.font = [UIFont systemFontOfSize:font];
        changeView.footerLabel.text = labeltext;
        changeView.footerLabel.textAlignment = NSTextAlignmentCenter;
        changeView.footerLabel.textColor = RGBACOLOR(89, 89, 89, 1);
        [df layerWithView:changeView.footerLabel radius:4 width:1 color:RGBACOLOR(89, 89, 89, 1)];
    }else if ([is_verified isEqualToString:@"1"]) {
        labeltext= @"已认证";
        CGRect rect = [df labelHeightWithContent:labeltext height:myinfoHeight font:font];
        changeView.footerLabel.frame = CGRectMake(changeView.frame.size.width-10-changeSize-rect.size.width, (myinfoHeight -rect.size.height-8)/2, rect.size.width+8, rect.size.height+8);
        changeView.footerLabel.font = [UIFont systemFontOfSize:font];
        changeView.footerLabel.text = labeltext;
        changeView.footerLabel.textAlignment = NSTextAlignmentCenter;
        changeView.footerLabel.textColor = RGBACOLOR(227, 72, 40, 1);
        [df layerWithView:changeView.footerLabel radius:4 width:1 color:RGBACOLOR(227, 72, 40, 1)];
    } else{
        labeltext= @"认证中";
        CGRect rect = [df labelHeightWithContent:labeltext height:myinfoHeight font:font];
        changeView.footerLabel.frame = CGRectMake(changeView.frame.size.width-10-changeSize-rect.size.width, (myinfoHeight -rect.size.height-8)/2, rect.size.width+8, rect.size.height+8);
        changeView.footerLabel.font = [UIFont systemFontOfSize:font];
        changeView.footerLabel.text = labeltext;
        changeView.footerLabel.textAlignment = NSTextAlignmentCenter;
        changeView.footerLabel.textColor = RGBACOLOR(227, 72, 40, 1);
        [df layerWithView:changeView.footerLabel radius:4 width:1 color:RGBACOLOR(227, 72, 40, 1)];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
